package org.boz.dial;

public class LispSym extends LispObject {
	private String m_name;

	public static LispObject assoc(LispObject o, LispObject alist) {
		if (alist == LispPrimitives.nil)
			return LispPrimitives.nil;
		if (alist.car().car() == o) {
			return alist.car();
		} else {
			return assoc(o, alist.cdr());
		}
	}

	public Object toObject() {
		if(m_name.equals("T"))
			return (Object)(new Boolean(true));
		if(m_name.equals("NIL"))
			return (Object)(new Boolean(false));
		return null;
	}
	
	public LispSym(String name) {
		m_name = name.toUpperCase();
	}

	public boolean equals(Object o) {
		if (o instanceof LispSym) {
			return ((LispSym) o).m_name.equals(m_name);
		}
		return false;
	}

	public String toString() {
		return m_name;
	}

	public String name() {
		return m_name;
	}

	public LispObject eval(LispObject env) {
		LispObject tmp = assoc(this, env);
		if (tmp == LispPrimitives.nil)
			throw new RuntimeException("Unbound symbol '" + m_name + "'");

		return tmp.cdr();
	}
}
